#ifndef HOMEBENCH_HOMECORE_HOMENET_HOMEHTTP_H
#define HOMEBENCH_HOMECORE_HOMENET_HOMEHTTP_H

#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtCore/QSaveFile>
#include <QtCore/QBuffer>

class QNetworkAccessManager;

class  Http : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
    Q_PROPERTY(QUrl url READ url WRITE setUrl)
    Q_PROPERTY(qint64 size WRITE setSize)


public:
    Http(QObject *parent = 0);
    virtual ~Http();


signals:
    void errorReported(const QString &errorString);

    void progressChanged(int value, int maximumValue);
public slots:
    void cancel();

    void download();

    void setFileName(QString arg)
    {
        m_fileName = arg;
    }

    void setUrl(QUrl arg)
    {
        m_url = arg;
    }


    QString fileName() const
    {
        return m_fileName;
    }

    QUrl url() const
    {
        return m_url;
    }

    void setSize(qint64 size)
    {
        m_size = size;
    }

protected:
    virtual void initialize(QNetworkReply *reply);
    virtual void remain(const QUrl &url);
private slots:
    void finished();

    void readyRead();

    void replyError(QNetworkReply::NetworkError);

    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
protected:
    QNetworkAccessManager *m_network;

    QNetworkReply *m_reply;

    bool m_aborted;

    QSaveFile m_file;

    QString m_fileName;

    QUrl m_url;

        qint64 m_size;
};


#endif // HOMEBENCH_HOMECORE_HOMENET_HOMEHTTP_H
